package com.suoyue.store.service.impl;

import com.suoyue.store.entity.Order;
import com.suoyue.store.mapper.OrderMapper;
import com.suoyue.store.service.ex.ServiceException;
import com.suoyue.store.service.iOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements iOrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public Integer insert(Integer uid, Integer pid, Integer num, Double total_price) {
        Integer rows=orderMapper.insert(uid,pid,num,total_price);
        if(rows!=1){
            throw new ServiceException("添加订单失败");
        }
        return rows;
    }

    @Override
    public List<Order> getListByPid(Integer pid) {
        List<Order> list=orderMapper.getOrderListByPid(pid);
        if(list.size()==0){
            throw new ServiceException("该商品无销售记录");
        }
        return list;
    }

    @Override
    public List<Order> getListByUid(Integer uid) {
        List<Order> list=orderMapper.getOrderListByUid(uid);
        if(list.size()==0){
            throw new ServiceException("该用户无购买记录");
        }
        return list;
    }
}
